/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package classes;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author Luy Lucas
 */
@Entity
@Table(name = "venda", catalog = "stellaris", schema = "")
@NamedQueries({
    @NamedQuery(name = "Venda.findAll", query = "SELECT v FROM Venda v"),
    @NamedQuery(name = "Venda.findByIdvenda", query = "SELECT v FROM Venda v WHERE v.vendaPK.idvenda = :idvenda"),
    @NamedQuery(name = "Venda.findByClienteIdcliente", query = "SELECT v FROM Venda v WHERE v.vendaPK.clienteIdcliente = :clienteIdcliente"),
    @NamedQuery(name = "Venda.findByVeiculoIdveiculo", query = "SELECT v FROM Venda v WHERE v.vendaPK.veiculoIdveiculo = :veiculoIdveiculo"),
    @NamedQuery(name = "Venda.findByValortotal", query = "SELECT v FROM Venda v WHERE v.valortotal = :valortotal"),
    @NamedQuery(name = "Venda.findByDesconto", query = "SELECT v FROM Venda v WHERE v.desconto = :desconto"),
    @NamedQuery(name = "Venda.findByValorliquido", query = "SELECT v FROM Venda v WHERE v.valorliquido = :valorliquido"),
    @NamedQuery(name = "Venda.findByData", query = "SELECT v FROM Venda v WHERE v.data = :data"),
    @NamedQuery(name = "Venda.findByFormapagamento", query = "SELECT v FROM Venda v WHERE v.formapagamento = :formapagamento")})
public class Venda implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected VendaPK vendaPK;
    @Basic(optional = false)
    @Column(name = "valortotal")
    private float valortotal;
    @Basic(optional = false)
    @Column(name = "desconto")
    private int desconto;
    @Basic(optional = false)
    @Column(name = "valorliquido")
    private float valorliquido;
    @Basic(optional = false)
    @Column(name = "data")
    @Temporal(TemporalType.DATE)
    private Date data;
    @Basic(optional = false)
    @Column(name = "formapagamento")
    private String formapagamento;

    public Venda() {
    }

    public Venda(VendaPK vendaPK) {
        this.vendaPK = vendaPK;
    }

    public Venda(VendaPK vendaPK, float valortotal, int desconto, float valorliquido, Date data, String formapagamento) {
        this.vendaPK = vendaPK;
        this.valortotal = valortotal;
        this.desconto = desconto;
        this.valorliquido = valorliquido;
        this.data = data;
        this.formapagamento = formapagamento;
    }

    public Venda(int idvenda, int clienteIdcliente, int veiculoIdveiculo) {
        this.vendaPK = new VendaPK(idvenda, clienteIdcliente, veiculoIdveiculo);
    }

    public VendaPK getVendaPK() {
        return vendaPK;
    }

    public void setVendaPK(VendaPK vendaPK) {
        this.vendaPK = vendaPK;
    }

    public float getValortotal() {
        return valortotal;
    }

    public void setValortotal(float valortotal) {
        float oldValortotal = this.valortotal;
        this.valortotal = valortotal;
        changeSupport.firePropertyChange("valortotal", oldValortotal, valortotal);
    }

    public int getDesconto() {
        return desconto;
    }

    public void setDesconto(int desconto) {
        int oldDesconto = this.desconto;
        this.desconto = desconto;
        changeSupport.firePropertyChange("desconto", oldDesconto, desconto);
    }

    public float getValorliquido() {
        return valorliquido;
    }

    public void setValorliquido(float valorliquido) {
        float oldValorliquido = this.valorliquido;
        this.valorliquido = valorliquido;
        changeSupport.firePropertyChange("valorliquido", oldValorliquido, valorliquido);
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        Date oldData = this.data;
        this.data = data;
        changeSupport.firePropertyChange("data", oldData, data);
    }

    public String getFormapagamento() {
        return formapagamento;
    }

    public void setFormapagamento(String formapagamento) {
        String oldFormapagamento = this.formapagamento;
        this.formapagamento = formapagamento;
        changeSupport.firePropertyChange("formapagamento", oldFormapagamento, formapagamento);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (vendaPK != null ? vendaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Venda)) {
            return false;
        }
        Venda other = (Venda) object;
        if ((this.vendaPK == null && other.vendaPK != null) || (this.vendaPK != null && !this.vendaPK.equals(other.vendaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "gui.Venda[ vendaPK=" + vendaPK + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
